#ifndef LOGICMANAGER_H
#define LOGICMANAGER_H

#include "dataDefination.h"
#include "xmlHandle.h"

#include <QList>
#include <QObject>

class QTimer;

class LogicManager : public QObject
{
    Q_OBJECT
public:
    explicit LogicManager(QObject *parent = 0);
    ~LogicManager();
    void test(int);

private:
    void killTimer(QTimer * timer);

signals:
	void messageUpdate(const QString & ip, const QList<recordInfo> & list);	//onMessageUpdated
	void userListChanged(const QList<userInfo> & list); //onContactListUpdated
        void loginStatusReceived(eLoginStatus stauts);	//onLoginResultReceived
        void networkStatusChanged(eNetworkStatus stauts);	//onNetworkStatusChanged
	//for network
	void sendData(const QString & ip, const QByteArray & data);	//onSendData
        void closeConnection(const QString & ip);	//onCloseConnection
        void abortConnection(const QString & ip);

        //for server
        void sendServerData(const QByteArray & data);   //onSendServerData
        void sendLogout();	//onCloseAll


public slots:
	void onSendLogout();	//closeWindow
        void onSendMessage(const QString & ip, const QString & message);	//sendMessage
	void onCloseConnection(const QString& ip);	//stopChating
	void onSendLogin(const QString & name);	//login
	//for network
        void onReceivedData(const QString & ip, const QByteArray & data);	//recieveData
        void onNotify(const QString & ip, int code);	//notify

        void onReceivedServerData(const QByteArray & data);
        void onServerNotify(int code);
        void onRecordSendError();

private slots:
    void onSendUserList(QList<userInfo> list);
    void onSendRecordInfo(QString ip, recordInfo info);
    void onSendStatus(QString ip, int code);
    void onSendPulse();

private:
    xmlHandle * mXml;
    recordListSet * mListSet;
    userInfo    * mSelf;
    QHash<QString, QString> * mHash;
    QList<userInfo> * mUserList;
    recordInfo * mMessage;
    QByteArray * mXmlData;

    QTimer * mTimer;
    QList<QTimer *> * mTimerList;
    QHash<QTimer *, recordInfo> * mRecordHash;
    QHash<QTimer *, QString> * mIpHash;
    QHash<unsigned short, QTimer *> * mIdHash;
    unsigned short mId;
};

#endif // LOGICMANAGER_H
